const state = () => ({
  historyList: window.sessionStorage.getItem("history") ? JSON.parse(window.sessionStorage.getItem("history")):[],
})
const getters = {
  historyList: (state) => state.historyList,
}
const mutations = {
 setHistory(state, data) {
    let d = {
      parent:data.split('/')[1],
      path:data
    }
    let flg = true;
   state.historyList.forEach((item,index) =>{
      if(item.parent === d.parent){
        flg = false
        state.historyList.splice(index,1,d)
      }
    })
    if(flg){
      state.historyList.push(d)
    }
    window.sessionStorage.setItem("history",JSON.stringify(state.historyList))
  },
}
const actions = {
  setHistory({commit}, data) {
    commit('setHistory',data)
  }
}
export default { state, getters, mutations, actions }